//--------------------------------------------------------------------
//     Author:Howe
//     Date: 2021-04-13 21:46:32 
//     Description:对此文件的更改可能会导致不正确的行为，并且如果重新生成代码，这些更改将会丢失。
//--------------------------------------------------------------------
using System;
using System.Threading.Tasks;
using Kylin.Wiki.Core;  
using Kylin.Wiki.Model.Entity;
using Kylin.Wiki.IService;
using Kylin.Wiki.Core.Extensions.AutofacManager;
using Kylin.Wiki.Repository;
using Kylin.Wiki.Model.Api;
using Kylin.Wiki.Model.View;
using System.Collections.Generic;
using Kylin.Wiki.Core.Enum;
using System.Linq;

namespace Kylin.Wiki.Services
{	
    /// <summary>
    /// Project_UserServices
    /// </summary>	
    public class Document_UserService : Service<Document_User>, IDocument_UserService,IDependency
    {

        private readonly IUserService _userService;

        public Document_UserService( 
            IUserService userService,
            IUnitOfWork unitOfWork, IRepository<Document_User> repository): base(unitOfWork, repository)
        {
            _userService = userService;
            base.UnitOfWork = unitOfWork;
            base.Repository = repository;
        }



        public ApiResult<List<DocumentUserVM>> GetDocumentUserList(int wikiId)
        {
            ApiResult<List<DocumentUserVM>> result = new ApiResult<List<DocumentUserVM>>();
            var document = base.FindFirst(x => x.ID == wikiId);
            if (document == null)
                return new ApiResult<List<DocumentUserVM>>(false, HttpStateCode.Error, "该Wiki不存在");
            var documentList = (from a in base.Find(x => x.DocumentID == wikiId)
                                join b in _userService.Find(x => 1 == 1) on a.UserID equals b.UserID
                                select new DocumentUserVM
                                {
                                    ID = a.ID,
                                    UserID = b.UserID,
                                    DisplayName = b.DisplayName,
                                    DocumentID = a.DocumentID,
                                    Permission = a.Permission,
                                    UserName = b.UserName
                                }).ToList();
            result.Data = documentList;
            return result;
        }

    }

} 
	